
<%@page import="qldc.pm.qlktcsdldc.dto.DanCuDTO"%>
<%@page import="qldc.pm.csdl.cd90.service.QuanHeVoiChuHoLocalServiceUtil"%>
<%@page import="qldc.pm.csdl.cd90.model.QuanHeVoiChuHo"%>
<%@page import="qldc.pm.qtht.dmdc.utils.DiaChiUtils"%>
<%@page import="qldc.pm.qlktcsdldc.utils.Utils"%>
<%@page import="qldc.pm.csdl.cd90.service.NoiThuongTruLocalServiceUtil"%>
<%@page import="qldc.pm.csdl.cd90.model.NoiThuongTru"%>
<%@page import="com.liferay.portal.kernel.util.Constants"%>
<%@page import="qldc.pm.qlktcsdldc.actions.ActionHandlerConstant"%>
<%@page import="qldc.pm.qtht.dmdc.service.TinhLocalServiceUtil"%>
<%@page import="qldc.pm.qtht.dmdc.model.Tinh"%>
<%@ include file="../init.jsp"%>

<%
	
	List<Tinh> tinhs = TinhLocalServiceUtil.findAll();
	String redirectURL = ParamUtil.getString(request, "redirect");
	PortletURL backURL = renderResponse.createRenderURL();
	backURL.setParameter("mvcPath", "/html/qlktcsdldc/quan_ly_dan_cu.jsp");
	backURL.setParameter("tabs1", QLKTCSDLDCContants.PAGEID_QLDC_MAN_HINH_CHINH);
	backURL.setParameter("redirect", redirectURL);
	
%>

<portlet:resourceURL var="loadQuanHuyen" id="loadQuanHuyen">
	<portlet:param name="tinhIdSelected" value="{0}" />
</portlet:resourceURL>

<portlet:resourceURL var="loadPhuongXa" id="loadPhuongXa">
	<portlet:param name="quanHuyenIdSelected" value="{0}" />
</portlet:resourceURL> 
<%-- 
<portlet:actionURL var="QLDC_ManHinhChinh_ExportDanCuURL">
	<portlet:param name="<%=ActionHandlerConstant.ACTION_HANDLER_PARAM%>" value="<%=ActionHandlerConstant.QUAN_LY_DAN_CU_ACTION%>" />
	<portlet:param name="<%=Constants.ACTION%>" value="ManHinhChinh_ExportDanCu" />
	<portlet:param name="redirect" value="<%=backURL.toString()%>" />
</portlet:actionURL>

<portlet:actionURL var="QLDC_ManHinhChinh_InURL">
	<portlet:param name="<%=ActionHandlerConstant.ACTION_HANDLER_PARAM%>" value="<%=ActionHandlerConstant.QUAN_LY_DAN_CU_ACTION%>" />
	<portlet:param name="<%=Constants.ACTION%>" value="ManHinhChinh_In" />
	<portlet:param name="redirect" value="<%=backURL.toString()%>" />
</portlet:actionURL> --%>
<portlet:actionURL var="QLDC_ManHinhChinhURL">
	<portlet:param name="<%=ActionHandlerConstant.ACTION_HANDLER_PARAM%>" value="<%=ActionHandlerConstant.QUAN_LY_DAN_CU_ACTION%>" />
	<portlet:param name="<%=Constants.ACTION%>" value="QLDC_ManHinhChinhAction" />
	<portlet:param name="redirect" value="<%=backURL.toString()%>" />
</portlet:actionURL>

<h2 class="tle-Content">
	<liferay-ui:message key="quan-ly-dan-cu" />
</h2>
<div class="main-Content">
	<form method="POST" target="_blank" action="<%=QLDC_ManHinhChinhURL.toString() %>" name="<portlet:namespace/>fmQLDC_ManHinhChinh" id="<portlet:namespace/>fmQLDC_ManHinhChinh">
		<aui:input name="<%= Constants.CMD %>" type="hidden" />
		<%
			long tinhId = ParamUtil.getLong(request, "tinh");
			long quanHuyenId = ParamUtil.getLong(request, "quanHuyen");
			long phuongXaId = ParamUtil.getLong(request, "phuongXa");
			String dCThuongTru = ParamUtil.getString(request, "dCThuongTru");
			String soDinhDanhCaNhan = ParamUtil.getString(request, "soDinhDanhCaNhan");
			String soCMND = ParamUtil.getString(request, "soCMND");
		%>
		<table class="gridnormal">
			<tr>
				<td>
					<liferay-ui:message key="tinh" />
				</td>
				
				<td>
					<select class=""  id="<portlet:namespace/>tinh"  name="<portlet:namespace/>tinh" 
					onchange="loadNewQuanHuyen('<portlet:namespace />','<%=loadQuanHuyen.toString()%>',<%=quanHuyenId%>,'tinh','quanHuyen', 'phuongXa');">
						<option value="0"><liferay-ui:message key="chon-tinh" /></option>
						<%
							for (Tinh tinh : tinhs) {
						%>
						<option value="<%=tinh.getTinhId()%>"
							<%=tinh.isLaMacDinh() ? "selected=selected" : ""%>><%=tinh.getTenTinh()%></option>
						<%
							}
						%>
					</select>
				</td>
				<td>
					<liferay-ui:message key="quan-huyen" />
				</td>
				
				<td>
					<select class=""  id="<portlet:namespace/>quanHuyen"  name="<portlet:namespace/>quanHuyen" 
						onchange="loadNewPhuongXa('<portlet:namespace />','<%=loadPhuongXa.toString()%>',<%=phuongXaId%>,'tinh','quanHuyen', 'phuongXa');">
						<option value="0"><liferay-ui:message key="chon-quan-huyen" /></option>
					</select>
				</td>
			</tr>

			<tr>
				<td>
					<liferay-ui:message key="phuong-xa" />
				</td>
				
				<td>
					<select class=""  id="<portlet:namespace/>phuongXa"  name="<portlet:namespace/>phuongXa">
						<option value="0"><liferay-ui:message key="chon-phuong-xa" /></option>
					</select>
				</td>
				<td>
					<liferay-ui:message key="dc-thuong-tru" />
				</td>
				<td>
					<input type="text" name="<portlet:namespace/>dCThuongTru" id="<portlet:namespace/>dCThuongTru" value="<%=(Validator.isNotNull(dCThuongTru)? dCThuongTru: "") %>" />
					
				</td>
			</tr>
			<tr>
				<td>
					<liferay-ui:message key="so-dinh-danh-ca-nhan" />
				</td>
				<td>
					<input type="text" name="<portlet:namespace/>soDinhDanhCaNhan" id="<portlet:namespace/>soDinhDanhCaNhan" value="<%=(Validator.isNotNull(soDinhDanhCaNhan)? soDinhDanhCaNhan:"") %>" />
				</td>
				<td>
					<liferay-ui:message key="so-cmnd" />
				</td>
				<td>
					<input type="text" name="<portlet:namespace/>soCMND" id="<portlet:namespace/>soCMND" value="<%=(Validator.isNotNull(soCMND)? soCMND:"")%>" />
				</td>
			</tr>
			<tr>
				<td colspan="4">
					
					<input type="button" class="" onclick="QLDC_ManHinhChinh_TimKiem()" value="<liferay-ui:message key="tim-kiem" />" id="<portl et:namespace/>timKiem" /> 
					<input type="button" class="" onclick="QLDC_ManHinhChinh_ExportDanCu()" value="<liferay-ui:message key="export-dan-cu" />"  id="<portlet:namespace/>exportDanCu" />
					<input type="button" class="" onclick="QLDC_ManHinhChinh_In()" value="<liferay-ui:message key="in" />"  id="<portlet:namespace/>in" />
				</td>
			</tr>
		</table>
		<liferay-ui:search-container emptyResultsMessage="no-web-content-were-found">
			<liferay-ui:search-container-results>
				<%
					results = NoiThuongTruLocalServiceUtil.QLTKDL_SearchCongDan(tinhId, quanHuyenId, phuongXaId, dCThuongTru, soDinhDanhCaNhan, soCMND, searchContainer.getStart(), searchContainer.getEnd());
					//total = NoiThuongTruLocalServiceUtil.QLTKDL_SearchCongDanSize(tinhId, quanHuyenId, phuongXaId, dCThuongTru, soDinhDanhCaNhan, soCMND, searchContainer.getStart(), searchContainer.getEnd());
					total = results.size();
					pageContext.setAttribute("results", results);
					pageContext.setAttribute("total", total);
				%>
			</liferay-ui:search-container-results>
			<%
				int start = 0;
			%>
			<liferay-ui:search-container-row className="java.lang.Object" modelVar="search">
				<%
					DanCuDTO _congDan = new DanCuDTO();
					if(((Object[])search)[0] != null)
						_congDan.setSoDinhDanhCaNhan(((Object[])search)[0].toString());
					if(((Object[])search)[1] != null)
						_congDan.setHoVaTen(((Object[])search)[1].toString());
					if(((Object[])search)[2] != null)
						_congDan.setNgaySinh(Utils.formatDateToStringSQL(((Object[])search)[2].toString()));
					if(((Object[])search)[3] != null)
						_congDan.setSoCMND(((Object[])search)[3].toString());
					if(((Object[])search)[4] != null)
						_congDan.setNgayCapCMND(Utils.formatDateToStringSQL(((Object[])search)[4].toString()));
					if(((Object[])search)[5] != null)
						_congDan.setGioiTinh(Integer.parseInt(((Object[])search)[5].toString()));
					if(((Object[])search)[6] != null)
						_congDan.setTinhId(Long.parseLong(((Object[])search)[6].toString()));
					if(((Object[])search)[7] != null)
						_congDan.setQuanHuyenId(Long.parseLong(((Object[])search)[7].toString()));
					if(((Object[])search)[8] != null)
						_congDan.setPhuongXaId(Long.parseLong(((Object[])search)[8].toString()));
					if(((Object[])search)[9] != null)
						_congDan.setDiaChi(((Object[])search)[9].toString());

					String _diaChi = DiaChiUtils.createBlockDiaChi(_congDan.getTinhId(), _congDan.getQuanHuyenId(), _congDan.getPhuongXaId(), _congDan.getDiaChi());
					String _soSoHoKhau ="";
					QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(_congDan.getSoDinhDanhCaNhan());
					if(Validator.isNotNull(quanHeVoiChuHo)){
						_soSoHoKhau = quanHeVoiChuHo.getSoSoHoKhau();
					}else{
						System.out.println("Khong tim thay quan he coi chu ho :"+ _congDan.getSoDinhDanhCaNhan());
					}
					String _gioiTinh = _congDan.getGioiTinh() == 1? LanguageUtil.get(portletConfig, request.getLocale(), "nam"):LanguageUtil.get(portletConfig, request.getLocale(), "nu");
				%>
				<liferay-ui:search-container-column-text cssClass="aui-w5 txt-center" name='<%=LanguageUtil.get(request.getLocale(), "stt")%>' value="<%=String.valueOf(++start)%>" />
				<liferay-ui:search-container-column-text cssClass="aui-w10 txt-center" name='<%=LanguageUtil.get(request.getLocale(), "so-ddcn")%>' value="<%=_congDan.getSoDinhDanhCaNhan()%>" />
				<liferay-ui:search-container-column-text cssClass="aui-w15 txt-center" name='<%=LanguageUtil.get(request.getLocale(), "ho-va-ten")%>' value="<%=_congDan.getHoVaTen()%>" />
				<liferay-ui:search-container-column-text cssClass="aui-w10 txt-center" name='<%=LanguageUtil.get(request.getLocale(), "ngay-sinh")%>' value="<%=_congDan.getNgaySinh()%>" />
				<liferay-ui:search-container-column-text cssClass="aui-w10 txt-center" name='<%=LanguageUtil.get(request.getLocale(), "so-cmnd")%>' value="<%=_congDan.getSoCMND()%>" />
				<liferay-ui:search-container-column-text cssClass="aui-w10 txt-center" name='<%=LanguageUtil.get(request.getLocale(), "ngay-cap-cmnd")%>' value="<%=_congDan.getNgayCapCMND()%>" />
				<liferay-ui:search-container-column-text cssClass="aui-w5 txt-center" name='<%=LanguageUtil.get(request.getLocale(), "gioi-tinh")%>' value="<%=_gioiTinh %>" />
				<liferay-ui:search-container-column-text cssClass="aui-w10 txt-center" name='<%=LanguageUtil.get(request.getLocale(), "so-so-ho-khau")%>' value="<%=_soSoHoKhau%>" />
				<liferay-ui:search-container-column-text cssClass="aui-w10 txt-center" name='<%=LanguageUtil.get(request.getLocale(), "dia-chi-thuong-tru")%>' value="<%=_diaChi%>" />
				<liferay-ui:search-container-column-text cssClass="aui-Action aui-w10 txt-center" align="right">
					<liferay-ui:icon-menu message="hanh-dong">
						<portlet:renderURL var="xemChiTietURL">
							<portlet:param name="mvcPath" value="/html/qlktcsdldc/quan_ly_dan_cu.jsp"/>
							<portlet:param name="soDinhDanhCaNhan" value="<%= _congDan.getSoDinhDanhCaNhan() %>" />
							<portlet:param name="tabs1" value="<%= QLKTCSDLDCContants.PAGEID_QLDC_XEM_CHI_TIET %>" />
						</portlet:renderURL>
						<liferay-ui:icon image="view" message="xem-chi-tiet" url="<%= xemChiTietURL.toString() %>" />
						
						<portlet:renderURL var="xemLichSuThayDoiURL">
							<portlet:param name="mvcPath" value="/html/qlktcsdldc/quan_ly_dan_cu.jsp"/>
							<portlet:param name="soDinhDanhCaNhan" value="<%= _congDan.getSoDinhDanhCaNhan() %>" />
							<portlet:param name="tabs1" value="<%= QLKTCSDLDCContants.PAGEID_QLDC_XEM_LICH_SU_THAY_DOI %>" />
						</portlet:renderURL>
						<liferay-ui:icon image="view" message="xem-lich-su-thay-doi" url="<%= xemLichSuThayDoiURL.toString() %>" />
						
						<portlet:renderURL var="suaThongTinURL">
							<portlet:param name="mvcPath" value="/html/qlktcsdldc/quan_ly_dan_cu.jsp"/>
							<portlet:param name="soDinhDanhCaNhan" value="<%= _congDan.getSoDinhDanhCaNhan() %>" />
							<portlet:param name="tabs1" value="<%= QLKTCSDLDCContants.PAGEID_QLDC_SUA_THONG_TIN %>" />
						</portlet:renderURL>
						<liferay-ui:icon image="edit" message="sua-thong-tin" url="<%= suaThongTinURL.toString() %>" />
						
						<portlet:renderURL var="kiemTraDuLieuURL">
							<portlet:param name="mvcPath" value="/html/qlktcsdldc/quan_ly_dan_cu.jsp"/>
							<portlet:param name="soDinhDanhCaNhan" value="<%= _congDan.getSoDinhDanhCaNhan() %>" />
							<portlet:param name="tabs1" value="<%= QLKTCSDLDCContants.PAGEID_QLDC_KIEM_TRA_DU_LIEU %>" />
						</portlet:renderURL>
						<liferay-ui:icon image="view" message="kiem-tra-du-lieu" url="<%= kiemTraDuLieuURL.toString() %>" />
						
						<%
							PortletURL url = renderResponse.createRenderURL();
							url.setParameter("mvcPath", "/html/qlktcsdldc/quan_ly_dan_cu.jsp");
							url.setParameter("tabs1", QLKTCSDLDCContants.PAGEID_QLDC_MAN_HINH_CHINH);
						%>
						
						<portlet:actionURL var="xuatThongTinRaFileURL" >
							<portlet:param name="redirect"  value="<%= url.toString() %>" />
							<portlet:param name="<%=ActionHandlerConstant.ACTION_HANDLER_PARAM%>" value="<%=ActionHandlerConstant.QUAN_LY_DAN_CU_ACTION%>" />
							<portlet:param name="<%=Constants.ACTION%>" value="xuatThongTinRaFile" />
							<portlet:param name="soDinhDanhCaNhan" value="<%= _congDan.getSoDinhDanhCaNhan() %>" />
						</portlet:actionURL>
						<liferay-ui:icon image="view" message="xuat-thong-tin-ra-file" url="<%= xuatThongTinRaFileURL.toString() %>" />
					</liferay-ui:icon-menu>
				</liferay-ui:search-container-column-text> 
			</liferay-ui:search-container-row>
			<liferay-ui:search-iterator searchContainer="<%=searchContainer%>" />

		</liferay-ui:search-container>
	</form>
</div>


<script type="text/javascript">
 $(document).ready(function() {
	loadNewQuanHuyen('<portlet:namespace />','<%=loadQuanHuyen.toString()%>',<%=quanHuyenId%>,'tinh','quanHuyen', 'phuongXa');
	loadNewPhuongXa('<portlet:namespace />','<%=loadPhuongXa.toString()%>',<%=phuongXaId%>,'tinh','quanHuyen', 'phuongXa');
});

function QLDC_ManHinhChinh_TimKiem(){	
	console.log('QLDC_ManHinhChinh_TimKiem');
	$('#<portlet:namespace/>fmQLDC_ManHinhChinh').removeAttr("target");
	$('#<portlet:namespace/>fmQLDC_ManHinhChinh').removeAttr("action");
	$('#<portlet:namespace/>cmd').val('<%=QLKTCSDLDCContants.TIM%>');
	$("#<portlet:namespace/>fmQLDC_ManHinhChinh").attr('onsubmit', 'return true;');
	$("#<portlet:namespace/>fmQLDC_ManHinhChinh").submit();
};
function QLDC_ManHinhChinh_ExportDanCu() {	
	console.log('QLDC_ManHinhChinh_ExportDanCu');
	showPopupConfirm('<liferay-ui:message key="ban-co-muon-luu-thong-tin" />',['Yes','No'],function(index){
		if (index == 0)
		{
			$('#<portlet:namespace/>cmd').val('<%=QLKTCSDLDCContants.EXPORT_FILE%>');
			$("#<portlet:namespace/>fmQLDC_ManHinhChinh").attr('action', '<%=QLDC_ManHinhChinhURL.toString() %>');
			$("#<portlet:namespace/>fmQLDC_ManHinhChinh").attr('target', '_blank');
			$("#<portlet:namespace/>fmQLDC_ManHinhChinh").submit();
		}
	});
};
function QLDC_ManHinhChinh_In() {	
	console.log('QLDC_ManHinhChinh_In');
	showPopupConfirm('<liferay-ui:message key="ban-co-muon-luu-thong-tin" />',['Yes','No'],function(index){
		if (index == 0)
		{
			$('#<portlet:namespace/>cmd').val('<%=QLKTCSDLDCContants.IN%>');
			$("#<portlet:namespace/>fmQLDC_ManHinhChinh").attr('action', '<%=QLDC_ManHinhChinhURL.toString() %>');
			$("#<portlet:namespace/>fmQLDC_ManHinhChinh").attr('target', '_blank');
			$("#<portlet:namespace/>fmQLDC_ManHinhChinh").submit();
		}
	});
}; 
</script>


